package essay

import (
	"log"

	essayStore "gitee.com/taadis/nook/store/essay"
)

type Essay struct {
	Id      string
	Title   string
	Content string
}

func Data(id string) (data Essay, err error) {
	essay, err := essayStore.Single(id)
	if err != nil {
		log.Println(err)
		return
	}
	data.Id = essay.Id
	data.Title = essay.Title
	data.Content = essay.Content
	return
}

// 随笔列表结构体
type Essays []Essay

// 随笔索引数据
func ListData() (data Essays, err error) {
	list, err := essayStore.Recent()
	if err != nil {
		log.Println(err.Error())
		return data, err
	}
	for _, item := range list {
		essay := Essay{
			Id:    item.Id,
			Title: item.Title,
		}
		data = append(data, essay)
	}
	return data, nil
}
